﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC_Class.Write.API.Application.Command.Permissions;
using RBAC_Class.Domain;
using RBAC_Class.ErrorCode;
using RBAC_Class.Infrastructrue.Interfaces;

namespace RBAC_Class.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        private readonly IMediator mediator;

        public PermissionController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        
        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="cmd">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public Task<APIResult<int>> AddPermission(AddPermissionCommand cmd)
        {
            return mediator.Send(cmd);
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="cmd">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public Task<APIResult<int>> DeletePermission(DeletePermissionCommand cmd)
        {
            return mediator.Send(cmd);
        }
        /// <summary>
        /// 修改权限
        /// </summary>
        /// <param name="cmd">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public Task<APIResult<int>> UpdatePermission(UpdatePermissionCommand cmd)
        {
            return mediator.Send(cmd);
        }
    }
}
